<template>
  <!--   eslint-disable -->
  <div style="width: 100vw; height: 100vh;display: flex;flex-direction:column;justify-content: center;">

    <div class="container">
      <div class="all-container animate__animated animate__bounceInRight">
        <!--      登录卡片左侧-->
        <div class="left-container">
          <el-row>
            <el-col :span="12">
              <div class="grid-content">
                <div style="margin: auto">
                  <div class="text" style="margin-right: 4%">管</div>
                  <div class="text">理</div>
                  <div class="text" style="margin-left: 4%">员</div>
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
        <!--      登录卡片右侧-->
        <div class="login-container">
          <!--        登录表单-->
          <el-form
            ref="loginForm"
            :model="loginForm"
            :rules="loginRules"
            class="login-form"
            auto-complete="on"
            label-position="left"
          >

            <div class="title-container">
              <h3 class="title">Admin Login</h3>
            </div>

            <el-form-item prop="phone_num" style="width: 80%">
          <span class="svg-container">
            <svg-icon icon-class="user"/>
          </span>
              <el-input
                ref="phone_num"
                v-model="loginForm.phone_num"
                placeholder="请输入电话号码"
                name="phone_num"
                type="text"
                tabindex="1"
                auto-complete="on"
              />
            </el-form-item>
            <el-form-item prop="imageCode" style="width: 80%">
              <div style="display: flex">
                <el-input
                  ref="imageCode"
                  v-model="loginForm.imageCode"
                  placeholder="请输入验证码"
                  name="imageCode"
                  type="text"
                  tabindex="1"
                  auto-complete="on"
                />
                <img ref="captchaImg" alt="验证码" @click="fetchCaptcha">
              </div>
            </el-form-item>

            <el-form-item prop="password" style="width: 80%">
          <span class="svg-container">
            <svg-icon icon-class="password"/>
          </span>
              <el-input
                ref="password"
                v-model="loginForm.password"
                placeholder="请输入密码"
                name="password"
                tabindex="2"
                auto-complete="on"
                @keyup.enter.native="handleLogin"
                show-password
              />
            </el-form-item>

            <el-button
              :loading="loading"
              type="primary"
              style="width:60%;"
              @click.native.prevent="handleLogin"
            >Login
            </el-button>
            <el-form-item
              style="background:rgba(255,255,255,0)"
              prop="isAgree"
            >
              <el-checkbox text-color="#cab5d9" v-model="loginForm.isAgree">已阅读并同意用户协议</el-checkbox>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* eslint-disable */


import {generateCaptcha} from "@/api/user";

export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        phone_num: process.env.NODE_ENV === 'development' ? '22' : '',
        password: process.env.NODE_ENV === 'development' ? '22' : '',
        isAgree: process.env.NODE_ENV === 'development',
        imageCode: ''
      },
      loginRules: {
        phone_num: [
          {required: true, trigger: 'blur', message: "请输入电话号码"},
          // {
          //   pattern: /1[3-9]\d{9}$/,
          //   message: "请输入正确电话号码"
          // }
        ],
        password: [{required: true, trigger: 'blur', message: "请输入密码"}],
        isAgree: [{
          validator: (rule, value, callback) => {
            value ? callback() : callback(new Error("请勾选用户协议"));
          }
        }]
      },
      loading: false,
      redirect: undefined
    }
  },
// computed: {
//   variables() {
//     return variables
//   }
// },
  mounted() {
    this.fetchCaptcha();
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect
      }
      ,
      immediate: true
    }
  },
  methods: {
    async fetchCaptcha() {
      const rep = await generateCaptcha();
      this.$refs.captchaImg.src = `data:image/png;base64,${rep}`
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          // alert("成功！")
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm).then(() => {
            this.$router.push('/')
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: linear-gradient(to right, #fbfcdb 0%, #e9defa 100%);
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

.container {
  position: absolute;
  content: '';
  top: 0;
  left: 0;
  width: 100%; /* 相对于 #app 的宽度 */
  height: 100%; /* 相对于 #app 的高度 */
  background-image: url("http://113.45.144.121:2024/banner3.jpeg");
}

.all-container {
  position: absolute;
  right: 0;
  display: flex;

  border-bottom-left-radius: 30vw;
  border-top-left-radius: 30vw;
  box-shadow: #c3d3fc 0px 20px 20px 0px;
  width: 60vw;
  height: 100vh;
  margin: auto;
  //background: linear-gradient(to right, #fff 0%, #fbfcdb 30%, #e9defa 100%);
  background: rgba(255, 255, 255, 0.82);
  overflow: hidden;


  .left-container {
    flex: 2;
  }

  /* reset element-ui css */
  .login-container:hover {
    flex: 4;
    //background-image: linear-gradient(-20deg, #e9defa 0%, #fbfcdb 100%);
    //background-image: linear-gradient(to top, #fddb92 0%, #d1fdff 100%);
    //background: linear-gradient(to right, #fff 0%, #fbfcdb 30%, #e9defa 100%);
  }

  .login-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 3;
    //background: linear-gradient(90deg, #e0c3fc 0%, #8ec5fc 100%);
    //background-image: linear-gradient(90deg, #20E2D7 0%, #F9FEA5 100%);
    //background-image: linear-gradient(to top, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%);
    //background-image: linear-gradient(to top, #fddb92 0%, #d1fdff 100%);
    transition: all 0.5s ease-in-out;

    .el-input {
      display: inline-block;
      height: 47px;
      width: 85%;

      input {
        background: transparent;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 12px 5px 12px 15px;
        color: $light_gray;
        height: 47px;
        caret-color: $cursor;

        &:-webkit-autofill {
          background: $bg;
          box-shadow: 0 0 0px 1000px $bg inset !important;
          -webkit-text-fill-color: $cursor !important;
        }
      }
    }

    .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }
  }
}

</style>

<style lang="scss" scoped>
$bg: linear-gradient(to right, #fbfcdb 0%, #e9defa 100%);
$dark_gray: #889aa4;
$light_gray: #ffffff;

.img {
  width: 100px;
  height: 100px;
  object-fit: contain; /* 保持图片比例，不裁剪 */
  /* 或 object-fit: cover;  （覆盖容器，可能裁剪部分内容） */
}

.all-container {
  transition: box-shadow 0.5s ease;
}

.all-container:hover {
  box-shadow: -20px -15px 20px 0px rgb(190, 233, 255), /* 第一层阴影，轻微的内发光 */
  0 0 20px rgb(127, 193, 255), /* 第二层阴影，更强的内发光 */
  0 0 30px rgb(255, 243, 210); /* 第三层阴影，较弱的外发光 */
}

.left-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .text {
    text-align: center;
    font-family: 华文行楷, sans-serif;
    font-size: 60px;
    transition: all 0.5s ease; /* 添加过渡效果 */
  }

  .text:hover {
    font-size: 100px;
    color: rgb(127, 193, 255);
  }

  .title {
    text-align: center;
    font-family: 华文行楷, sans-serif;
    font-size: 15px;
    transition: font-size 0.5s ease; /* 添加过渡效果 */
  }

  .title:hover {
    font-size: 80px;
    color: rgb(127, 193, 255);
  }
}

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;
    text-shadow: 7px 2px 4px #a9bdff;

    .title {
      font-size: 30px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
